#ifndef __CLIENT_OBJECT_MANAGER__
#define __CLIENT_OBJECT_MANAGER__

#include "Scene.h"

#include <list>
#include <vector>
#include <cassert>

#include "Msg\hzCommander.h"
#include "..\Common\CommonObject.h"
#include "..\Common\CommonNetwork.h"
#include "..\Common\CommonMessage.h"

#include "ClientBase.h"



class service_requester;

class object_manager : public CScene {
public:
	struct client_access_info { // other client info structure. 
		unsigned int	ClientCode;
		ip				IP;
		unsigned int	UdpPort;
		// for debug order's values. 
		unsigned int	LastUdpRecvCount;
		unsigned int	UdpRecvCountForFrame;
		unsigned int	LastEffectiveUdpRecvCountForFrame;
		unsigned int	EffectiveUdpRecvCountForFrame;
		unsigned int	LastUpdateTick;
		unsigned int	UdpLinkCount;

		client_access_info(unsigned int NewClientCode, ip NewIP, unsigned int NewUdpPort) 
			:	ClientCode(NewClientCode), IP(NewIP), UdpPort(NewUdpPort), 
				UdpRecvCountForFrame(0), LastUpdateTick(0), LastUdpRecvCount(0),
				LastEffectiveUdpRecvCountForFrame(0),EffectiveUdpRecvCountForFrame(0), UdpLinkCount(0) {	 }
	};

	typedef std::list<client_access_info> client_info_list;

private:
	// other component's ptr.
	client_base*		m_pClient;
	service_requester*	m_pServiceRequester;	
	hz::commander*		m_pCommander;	
		
	network*			m_UdpNetwork;
	unsigned int		m_ShipCode;
	client_info_list	m_OtherClientInfo;
	
	// for debug order.
	bool			m_ShowRecvSyncDataCount;
	bool			m_ShowEffectiveRecvSyncDataCount;
	bool			m_ShowMySendSyncDataCount;
	unsigned int	m_LastMySendSyncDataCount;
	unsigned int	m_CurrentMySendSyncDataCount;
	unsigned int	m_LastUpdateMySendSyncDataTick;
	bool			m_PosInterpolation;	

public:
	object_manager(void);
	~object_manager(void);

	void LinkClient(client_base* pClient);
	void LinkServiceRequester(service_requester* pServiceRequester);	
	void LinkCommander(hz::commander* pCommander);
	void SetUDP(network* pUdpNetwork);

	client_info_list GetClientList(void);
	void ConnectOtherClients(void);									// try udp link
	void ConnectTargetClient(ip TargetIP, unsigned int UdpPort);	// try udp link
	void TryUdpLink(unsigned int ClientCode);	// called at client recv other client's link data. 

	bool AddClient(ip ClientIP, unsigned int ClientCode, unsigned int PortNumber);
	bool DeleteClient(const unsigned int& ClientCode);
	bool AddObject(const unsigned int& ObjectID, const OBJECT_TYPE& ObjectType, const unsigned int& OwnerCode, 
				   const int& ExtraLength, const char* Extra);
	bool DeleteObject(const unsigned int& ObjectID);

	bool UpdateOtherClientObject(sync_object_3d* SyncData);
	bool UpdateObject(float ElapsedTime);			
	bool UpdateCommander(void);			// print debug message. 
	//void MotionUpdate(void);			// motion update method. but network's event too slow. so now working to thread

	bool FireMissile(void);	

	// for debug order.
	bool SwitchShowRecvSyncDataCount(void);
	bool SwitchShowEffectiveRecvSyncDataCount(void);
	bool SwitchShowMySendSyncDataCount(void);
	bool SwitchPosInterpolation(void);	
};

#endif
